class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]


class ConsoleLog(metaclass=Singleton):
    def __init__(self, c, enc='utf-8'):
        self.arg = c.logcat
        self.enc = enc
        arg = self.arg

        if arg == "console":
            self.using_method = print
        else:
            self.fileHandle = open(arg, 'a+', encoding=enc)
            self.using_method = self.write_file

    def write_file(self, txt):
        self.fileHandle = open(self.arg, 'a+', encoding=self.enc)
        self.fileHandle.writelines(txt + "\n")
        self.fileHandle.close()


